package pl.edu.agh.pros.node;

import org.ros.exception.ServiceException;
import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.service.ServiceResponseBuilder;
import org.ros.node.service.ServiceServer;

import std_srvs.Empty.Request;
import std_srvs.Empty.Response;

@SuppressWarnings("nls")
public class RosServiceServer extends AbstractNodeMain {

	private static final String SERVICE_NAME = "/test_service"; //$NON-NLS-1$
	private static final String SERVICE_TYPE = "std_srvs/Empty"; //$NON-NLS-1$

	@Override
	public GraphName getDefaultNodeName() {
		return new GraphName("pros_core/rosServiceServer"); //$NON-NLS-1$
	}

	@Override
	public void onStart(ConnectedNode node) {
		try {
			System.out.println("Starting a Testing Service Server Node........"); //$NON-NLS-1$
			@SuppressWarnings("unused")
			ServiceServer<Request, Response> server = node.newServiceServer(SERVICE_NAME, SERVICE_TYPE,
					new ServiceResponseBuilder<std_srvs.Empty.Request, std_srvs.Empty.Response>() {
						@Override
						public void build(std_srvs.Empty.Request request, std_srvs.Empty.Response response)
								throws ServiceException {
							System.out.println("Server: received request from client.");
						}
					});
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
